﻿using CSharpDay13Nov10.Adapters.Interfaces;
using CSharpDay13Nov10.Data;
using CSharpDay13Nov10.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSharpDay13Nov10.Adapters.Adapters
{
    public class ToDoAdapter : IToDoAdapter
    {
        public List<ToDoVM> GetAllToDo(string userId)
        {
            List<ToDoVM> model;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.ToDos.Where(x => x.IsDeleted == false && x.UserId == userId).Select(x => new ToDoVM()
                {
                    IsDeleted = false,
                    Task = x.Task,
                    ToDoId = x.ToDoId,
                    UserId = userId
                }).ToList();
            }
            return model;
        }


        public List<ToDoVM> GetAllToDoAdmin()
        {
            List<ToDoVM> model;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.ToDos.Where(x => x.IsDeleted == false).Select(x => new ToDoVM()
                {
                    IsDeleted = false,
                    Task = x.Task,
                    ToDoId = x.ToDoId,
                    UserId = x.UserId
                }).ToList();
            }
            return model;
        }
    }
}